/*
 * ConfigProperties.java
 *
 * Copyright(c) 2010
 * Michael Kroez
 * kroez@studiorutton.de
 *
 * All rights reserved.
 *
 * $Id$
 * 
 */

package de.studiorutton.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import android.content.Context;
import android.content.res.AssetManager;
import android.content.res.Resources;
import android.util.Log;

public class ConfigProperties {
	private final static String TAG = "learningwords";
	
	public static final String BASE_URL = "baseURL";
	public static final String APP_NAME = "appName";

	private Properties properties;
	private Resources resources;
	private final static String defaultProperties = "default.properties";
	private final static String testProperties = "test.properties";
	
	public ConfigProperties( Context context ) {
		this.resources = context.getResources();
		properties = new Properties();
		loadProperties( defaultProperties );
	}
	
	public void loadProperties( String propertiesFile ) {
		AssetManager assetManager = resources.getAssets();

		// Read from the /assets directory
		try {
		    InputStream inputStream = assetManager.open( propertiesFile );
		    properties.load(inputStream);
//		    Log.d( TAG, "The properties are now loaded. ");
		} catch (IOException e) {
//			Log.d( TAG, "Failed to open " + propertiesFile + " property file: " + e.getMessage() );
		}
	}
	
	public void loadDefaultProperties() {
		loadProperties( defaultProperties );
	}
	
	public void loadTestProperties() {
		loadProperties( testProperties );
	}
	
	public Properties getProperties() {
		return properties;
	}
	
}
